package com.diy.sigmund.diyorder.feign.fallback;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.entity.enumerate.ResponseEnum;
import com.diy.sigmund.diyorder.entity.dto.UserAuthDTO;
import com.diy.sigmund.diyorder.feign.client.UserClient;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ylm-sigmund
 * @since 2021/5/24 20:23
 */
@Component
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {

    private static final Logger LOG = LoggerFactory.getLogger(UserClientFallbackFactory.class);

    @Override
    public UserClient create(Throwable throwable) {
        LOG.warn(this.getClass().getSimpleName() + "进入熔断");
        return new UserClient() {
            @Override
            public ResultMsg login(UserAuthDTO dto) {
                return ResultMsg.fail(ResponseEnum.INTERNAL_SERVER_BUSY);
            }

            @Override
            public ResultMsg receiveFile(MultipartFile file, MultipartFile file1, String name, String phone) {
                return ResultMsg.fail(ResponseEnum.INTERNAL_SERVER_BUSY);
            }
        };
    }
}
